home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
ag68kmot.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
22KB
|
510 lines
{
$Id: ag68kmot.pas,v 1.1.1.1.2.3 1998/09/14 18:56:26 carl Exp $
Copyright (c) 1998 by the FPC development team
This unit implements an asmoutput class for MOTOROLA syntax with
Motorola 68000 (recognized by the Amiga Assembler and Charlie Gibbs's
A68k)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit ag68kmot;
interface
uses aasm,assemble;
type
pm68kmotasmlist=^tm68kmotasmlist;
tm68kmotasmlist = object(tasmlist)
procedure WriteTree(p:paasmoutput);virtual;
procedure WriteAsmList;virtual;
end;
implementation
uses
dos,globals,systems,cobjects,m68k,
strings,files,verbose
{$ifdef GDB}
,gdb
{$endif GDB}
;
const
line_length = 70;
function getreferencestring(const ref : treference) : string;
var
s : string;
begin
s:='';
if ref.isintvalue then
s:='#'+tostr(ref.offset)
else
with ref do
begin
if (index=R_NO) and (base=R_NO) and (direction=dir_none) then
begin
if assigned(symbol) then
begin
s:=s+symbol^;
if offset<0 then
s:=s+tostr(offset)
else
if (offset>0) then
s:=s+'+'+tostr(offset);
end
else
begin
{ direct memory addressing }
s:=s+'('+tostr(offset)+').l';
end;
end
else
begin
if assigned(symbol) then
s:=s+symbol^;
if offset<0 then
s:=s+tostr(offset)
else
if (offset>0) then
begin
if (symbol=nil) then s:=tostr(offset)
else s:=s+'+'+tostr(offset);
end;
if (index<>R_NO) and (base=R_NO) and (direction=dir_none) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
begin
if offset = 0 then
s:=s+'0(,'+mot_reg2str[index]+'.l)'
else
s:=s+'(,'+mot_reg2str[index]+'.l)';
end
else
begin
if offset = 0 then
s:=s+'0(,'+mot_reg2str[index]+'.l*'+tostr(scalefactor)+')'
else
s:=s+'(,'+mot_reg2str[index]+'.l*'+tostr(scalefactor)+')';
end
end
else
if (index=R_NO) and (base<>R_NO) and (direction=dir_inc) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'('+mot_reg2str[base]+')+'
else
InternalError(10002);
end
else
if (index=R_NO) and (base<>R_NO) and (direction=dir_dec) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+'-('+mot_reg2str[base]+')'
else
InternalError(10003);
end
else
if (index=R_NO) and (base<>R_NO) and (direction=dir_none) then
begin
s:=s+'('+mot_reg2str[base]+')';
end
else
if (index<>R_NO) and (base<>R_NO) and (direction=dir_none) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
begin
if offset = 0 then
s:=s+'0('+mot_reg2str[base]+','+mot_reg2str[index]+'.l)'
else
s:=s+'('+mot_reg2str[base]+','+mot_reg2str[index]+'.l)';
end
else
begin
if offset = 0 then
s:=s+'0('+mot_reg2str[base]+','+mot_reg2str[index]+'.l*'+tostr(scalefactor)+')'
else
s:=s+'('+mot_reg2str[base]+','+mot_reg2str[index]+'.l*'+tostr(scalefactor)+')';
end
end
{ if this is not a symbol, and is not in the above, then there is an error }
else
if NOT assigned(symbol) then
InternalError(10004);
end; { endif }
end; { end with }
getreferencestring:=s;
end;
function getopstr(t : byte;o : pointer) : string;
var
hs : string;
i: tregister;
begin
case t of
top_reg : getopstr:=mot_reg2str[tregister(o)];
top_reglist: begin
hs:='';
for i:=R_NO to R_FPSR do
begin
if i in tregisterlist(o^) then
hs:=hs+mot_reg2str[i]+'/';
end;
delete(hs,length(hs),1);
getopstr := hs;
end;
top_ref : getopstr:=getreferencestring(preference(o)^);
top_const : getopstr:='#'+tostr(longint(o));
top_symbol : begin
{ compare with i386 version, where this is a constant. }
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
{ inc(byte(hs[0]));}
{ hs[1]:='#';}
if pcsymbol(o)^.offset>0 then
hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
else if pcsymbol(o)^.offset<0 then
hs:=hs+tostr(pcsymbol(o)^.offset);
getopstr:=hs;
end;
else internalerror(10001);
end;
end;
function getopstr_jmp(t : byte;o : pointer) : string;
var
hs : string;
begin
case t of
top_reg : getopstr_jmp:=mot_reg2str[tregister(o)];
top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
top_const : getopstr_jmp:=tostr(longint(o));
top_symbol : begin
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
if pcsymbol(o)^.offset>0 then
hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
else if pcsymbol(o)^.offset<0 then
hs:=hs+tostr(pcsymbol(o)^.offset);
getopstr_jmp:=hs;
end;
else internalerror(10001);
end;
end;
{****************************************************************************